package ru.susu.algebra.centralunits.alternating.tex;

import java.util.List;

import com.google.common.collect.Lists;

import ru.susu.algebra.centralunits.alternating.MathMethodWithInitializers;
import ru.susu.algebra.centralunits.alternating.initializers.SpecialRowsInitializer;
import ru.susu.algebra.chartable.constructor.AlternatingCharTableUtil;
import ru.susu.algebra.jtex.ITexElement;
import ru.susu.algebra.jtex.StringTexElement;
import ru.susu.algebra.jtex.UnionTexElement;
import ru.susu.algebra.jtex.formula.FormulaTexElement;
import ru.susu.algebra.jtex.formula.GreekSymbols;
import ru.susu.algebra.jtex.utils.TexUtils;
import ru.susu.algebra.partition.Partition;
import ru.susu.algebra.properties.IPropertySource;

/**
 * @author akargapolov
 * @since: 26.08.2010
 */
public class SpecialNotIntegerRowsEnumerator extends MathMethodWithInitializers<ITexElement>
{
	private static final Class[] DEPENDENCIES = {SpecialRowsInitializer.class};

	private String getSpecialRowsInfo(IPropertySource ps) throws Exception
	{
		List<ITexElement> elements = Lists.newArrayList();

		for (Partition p1 : SpecialRowsInitializer.listSpecialNotIntegerCharacterRows(ps))
		{
			if (!elements.isEmpty())
				elements.add(StringTexElement.text(", "));
			elements.add(FormulaTexElement.formula(GreekSymbols.CHI + "=" + GreekSymbols.CHI + SpecialRowsInitializer.getIndexByRowNumber(ps, p1)));
			elements.add(StringTexElement.text(" степени "));
			elements.add(FormulaTexElement.formula(AlternatingCharTableUtil.calcAlternatingDegree(p1) + ""));
		}
		elements.add(StringTexElement.text("."));

		return TexUtils.processElements(elements);
	}

	@Override
	protected ITexElement directRun(IPropertySource ps) throws Exception
	{
		//перечисление особых характеров
		return new UnionTexElement()
				.addSubElement(StringTexElement.text("Будем изучать $u\\left(" + GreekSymbols.LAMBDA + "\\right)$" +
						" для характер" + (SpecialRowsInitializer.listSpecialNotIntegerCharacterRows(ps).size() == 1 ? "а " : "ов ") + getSpecialRowsInfo(ps)))
				.addSubElement(StringTexElement.newLineDouble());
	}

	@Override
	protected Class[] getDependentInitializers()
	{
		return DEPENDENCIES;
	}

}
